﻿<cfsilent>
	<cfscript>

		event.setArg("pageTitle", "学生门户");

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		propAdvice = getProperty("serviceFactory").getBean("schemaPropertyAdvice");
		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		classId = sessionAdvice.getUserProp("studentClass");
		subjectId = sessionAdvice.getUserProp("studentSubject");
		dirId = sessionAdvice.getUserProp("studentSubDir");
		
		/*
			学生??待定
			
		*/
		
		grade_t = sessionAdvice.getUserProp("studentGrade");
		
		grade = 0;
		
		term_t = right(grade_t,1);
		year_t = left(grade_t,4);

		if(term_t eq 1){
			grade = year_t-1;
		}else if(term_t eq 2){
			grade = year_t;
		}
	

		/* 学期相关信息 */
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		/* 专业信息 */
		sql = "SELECT sbj_name FROM t_subject WHERE sbj_id = :subjectId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );

		rs_subject = queryObj.execute( sql=sql ).getResult();

		/* 培养方案学分、课程分布概况 */
		sql = "SELECT 
				t_schema.term_index, COUNT(*), 
				SUM(CASE WHEN t_schema.prop_id = '1' THEN t_course.course_credit ELSE 0 END) credit_req, 
				SUM(CASE WHEN t_schema.prop_id = '2' THEN t_course.course_credit ELSE 0 END) credit_opt, 
				SUM(CASE WHEN t_schema.prop_id = '1' THEN 1 ELSE 0 end) course_req, 
				SUM(CASE WHEN t_schema.prop_id = '2' THEN 1 ELSE 0 end) course_opt 
				FROM t_schema 
				INNER JOIN t_course ON t_course.cid = t_schema.cid 
				WHERE 
					grade = :grade 
					and 
					( sbj_id = :subjectId or sbj_id like :subjectDirs ) 
				GROUP BY term_index
				ORDER BY term_index ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="subjectDirs", value=subjectId & "_", cfsqltype="cf_sql_varchar" );

		rs_summary = queryObj.execute( sql=sql ).getResult();
		
		
		/* 毕业学分要求等条件 */
		sql = "SELECT 
				credit, credit_required, credit_optional, credit_relish, period, period_required, period_optional
				FROM t_condition
				WHERE 
					con_id = :schemaId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="schemaId", value=grade & subjectId, cfsqltype="cf_sql_varchar" );
		
		rs_condition = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取学生当前学年的培养方案 */
		sql = "SELECT DISTINCT term_index, academic_year
				FROM t_schema 
				WHERE 
					grade = :grade 
					and 
					( sbj_id = :subjectId or sbj_id like :subjectDirs ) 
				ORDER BY 
					term_index ASC ";

		queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="subjectDirs", value=subjectId & "_", cfsqltype="cf_sql_varchar" );
		
		rs_schema_term = queryObj.execute( sql=sql ).getResult();
		
		//writedump( rs_schema_term );
		//abort;

		/* 判断当前标签显示 */
		currentTab = event.getArg("TabID", "labStatus");

		targetArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 collection"></i>个人学业规划（<font color="#FF0000">仅作参考</font>）
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labStatus">class="active"</cfif> id="labStatus" tabTarget="Status">学业概况</span>
						<cfloop query="rs_schema_term">
							<cfset lableTerm = mathAdvice.convertTermIdxToChinese( rs_schema_term.term_index ) />
							<span <cfif currentTab eq "labSchema" & rs_schema_term.term_index >class="active"</cfif> id="labSchema<cfoutput>#rs_schema_term.term_index#</cfoutput>" tabTarget="Schema<cfoutput>#rs_schema_term.term_index#</cfoutput>"><cfoutput>#lableTerm#</cfoutput></span>
						</cfloop>						
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Status" class="tabContent">
					
					<div class="noticeBlock">
						<h3>主修专业 - <cfoutput>#rs_subject.sbj_name#</cfoutput> 学期课程分布</h3>
					</div>
					
					<cfif rs_summary.recordCount>
						<table class="UItable">
							<tr align="center">
								<td class="cellBorderPadding" colspan="2">学期</td>
								<cfloop query="rs_summary">
									<cfset structInsert(targetArgs, "Term", rs_summary.term_index, true) />
									<td class="cellBorderPadding"><cfoutput>#mathAdvice.convertTermIdxToChinese( rs_summary.term_index )#</cfoutput></td>
								</cfloop>
								<cfset structDelete(targetArgs, "Term") />
							</tr>
							<tr align="center">
								<td width="12" class="cellBorderPadding" rowspan="2">学分</td>
								<td class="cellBorder">必修</td>
								<cfloop query="rs_summary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#numberFormat( rs_summary.credit_req , '0.0' )#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td class="cellBorder">选修</td>
								<cfloop query="rs_summary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#numberFormat( rs_summary.credit_opt , '0.0' )#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td width="12" class="cellBorderPadding" rowspan="2">课程</td>
								<td class="cellBorder">必修</td>
								<cfloop query="rs_summary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#rs_summary.course_req#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td class="cellBorder">选修</td>
								<cfloop query="rs_summary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#rs_summary.course_opt#</cfoutput></span></td>
								</cfloop>
							</tr>
						</table>
					</cfif>
					
				<!---	<cfif rs_condition.recordCount>
						
						<div class="noticeBlock">
							<h3>主修专业毕业学分要求</h3>
							<cfif ( rs_condition.credit + rs_condition.credit_required + rs_condition.credit_optional + rs_condition.credit_relish ) gt 0>
								<p>毕业时已获得课程学分必须达到如下条件</p>
								<ol>
									<cfif rs_condition.credit gt 0><li>总学分 <strong><cfoutput>#numberFormat( rs_condition.credit, "_._" )#</cfoutput></strong></li></cfif>
									<cfif rs_condition.credit_required gt 0><li>必修课 <strong><cfoutput>#numberFormat( rs_condition.credit_required, "_._" )#</cfoutput></strong></li></cfif>
									<cfif rs_condition.credit_optional gt 0><li>选修课 <strong><cfoutput>#numberFormat( rs_condition.credit_optional, "_._" )#</cfoutput></strong></li></cfif>
									<cfif rs_condition.credit_relish gt 0><li>全校性通选课学分 <strong><cfoutput>#numberFormat( rs_condition.credit_relish, "_._" )#</cfoutput></strong></li></cfif>
								</ol>
							<cfelse>
								<p>学院暂未设置该专业毕业学分要求</p>
							</cfif>
						</div>
						
						<cfif ( rs_condition.period + rs_condition.period_required + rs_condition.period_optional ) gt 0>
							<div class="noticeBlock">
								<h3>主修专业修读学时要求</h3>
								<ol>
									<cfif rs_condition.period gt 0><li>总学时 <strong><cfoutput>#rs_condition.period#</cfoutput></strong></li></cfif>
									<cfif rs_condition.period_required gt 0><li>必修课 <strong><cfoutput>#rs_condition.period_required#</cfoutput></strong></li></cfif>
									<cfif rs_condition.period_optional gt 0><li>选修课 <strong><cfoutput>#rs_condition.period_optional#</cfoutput></strong></li></cfif>
								</ol>
							</div>
						</cfif>
						
					</cfif>--->
					
				</div>
				
				<cfloop query="rs_schema_term">
					<div id="Schema<cfoutput>#rs_schema_term.term_index#</cfoutput>" class="tabContent">

						<cfscript>
							
							/* 专业课 */
							sql = "SELECT 
									t_course.course_name, 
									t_course.course_credit, 
									t_institute.institute_short, 
									t_course_prop.prop_name, 
									t_course_nature.cna_name, 
									t_course.period_theory, 
									t_course.period_practice, 
									t_course.period_computer, 
									t_course.course_code,
									shm_prop
									FROM t_schema 
									INNER JOIN t_course ON t_course.cid = t_schema.cid 
									INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id
									INNER JOIN t_course_prop ON t_course_prop.prop_id = t_schema.prop_id 
									INNER JOIN t_course_nature ON t_course_nature.cna_id = t_schema.cna_id 
									WHERE 
										grade = :grade 
										AND 
										sbj_id = :subjectId 
										AND 
										term_index = :term 
									ORDER BY 
										t_course_nature.cna_name, t_course_prop.prop_name, t_course.course_name";
		
							queryObj = new Query( datasource=application.dnsSlave );
							queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
							queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
							queryObj.addParam( name="term", value=rs_schema_term.term_index, cfsqltype="cf_sql_char" );
		
							rs_schema = queryObj.execute( sql=sql ).getResult();
							
							
							/* 方向课 */
							sql = "SELECT 
									t_course.course_name, 
									t_course.course_credit, 
									t_institute.institute_short, 
									t_course_prop.prop_name, 
									t_course_nature.cna_name, 
									t_course.period_theory, 
									t_course.period_practice, 
									t_course.period_computer, 
									t_course.course_code,
									shm_prop
									FROM t_schema 
									INNER JOIN t_course ON t_course.cid = t_schema.cid 
									INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id
									INNER JOIN t_course_prop ON t_course_prop.prop_id = t_schema.prop_id 
									INNER JOIN t_course_nature ON t_course_nature.cna_id = t_schema.cna_id 
									WHERE 
										grade = :grade 
										AND 
										sbj_id = :subjectDir 
										AND 
										term_index = :term 
									ORDER BY 
										t_course_nature.cna_name, t_course_prop.prop_name, t_course.course_name";
		
							queryObj = new Query( datasource=application.dnsSlave );
							queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
							queryObj.addParam( name="subjectDir", value=subjectId & dirId, cfsqltype="cf_sql_varchar" );
							queryObj.addParam( name="term", value=rs_schema_term.term_index, cfsqltype="cf_sql_char" );
		
							rs_schema_dir = queryObj.execute( sql=sql ).getResult();
							
						</cfscript>

						<div class="noticeBlock">
							<h3><cfoutput>#mathAdvice.convertTermIdxToChinese( rs_schema_term.term_index )#</cfoutput>计划课程</h3>
							<hr/>
						</div>
							
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="60">类别</td>
									<td width="60">课程性质</td>
									<td width="60">开课学院</td>
									<td width="80">课程号</td>
									<td>课程</td>
									<td width="30">理论</td>
									<td width="30">实践</td>
									<td width="30">上机</td>
									<td width="30">学分</td>
									<td width="36">学位课</td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
								<cfloop query="rs_schema">
									<cfset propAdvice.parseProperty( rs_schema.shm_prop ) />
									<cfset row++ />
									<tr class="editRows">
										<td><span class="index">P<cfoutput>#numberformat(row, "0_")#</cfoutput></span></td>
										<td><cfoutput>#rs_schema.cna_name#</cfoutput></td>
										<td><cfoutput>#rs_schema.prop_name#</cfoutput></td>
										<td><cfoutput>#rs_schema.institute_short#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_schema.course_code#</cfoutput></span></td>
										<td><cfoutput>#rs_schema.course_name#</cfoutput></td>
										<td align="center"><cfif rs_schema.period_theory gt 0><span class="numeric"><cfoutput>#rs_schema.period_theory#</cfoutput></span></cfif></td>
										<td align="center"><cfif rs_schema.period_practice gt 0><span class="numeric"><cfoutput>#rs_schema.period_practice#</cfoutput></span></cfif></td>
										<td align="center"><cfif rs_schema.period_computer gt 0><span class="numeric"><cfoutput>#rs_schema.period_computer#</cfoutput></span></cfif></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_schema.course_credit, "_.__" )#</cfoutput></span></td>
										<td align="right"><cfif propAdvice.getDegreeCourse()><span class="stat yes"></span></cfif></td>
									</tr>
								</cfloop>
								
								<cfif rs_schema_dir.recordCount>
									<tr class="breakRows">
										<td colspan="9"></td>
									</tr>
								</cfif>
								
								<cfset row = 0 />
								<cfloop query="rs_schema_dir">
									<cfset propAdvice.parseProperty( rs_schema_dir.shm_prop ) />
									<cfset row++ />
									<tr class="editRows">
										<td><span class="index">D<cfoutput>#numberformat(row, "0_")#</cfoutput></span></td>
										<td><cfoutput>#rs_schema_dir.cna_name#</cfoutput></td>
										<td><cfoutput>#rs_schema_dir.prop_name#</cfoutput></td>
										<td><cfoutput>#rs_schema_dir.institute_short#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_schema_dir.course_code#</cfoutput></span></td>
										<td><cfoutput>#rs_schema_dir.course_name#</cfoutput></td>
										<td align="center"><cfif rs_schema_dir.period_theory gt 0><span class="numeric"><cfoutput>#rs_schema_dir.period_theory#</cfoutput></span></cfif></td>
										<td align="center"><cfif rs_schema_dir.period_practice gt 0><span class="numeric"><cfoutput>#rs_schema_dir.period_practice#</cfoutput></span></cfif></td>
										<td align="center"><cfif rs_schema_dir.period_computer gt 0><span class="numeric"><cfoutput>#rs_schema_dir.period_computer#</cfoutput></span></cfif></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_schema_dir.course_credit, "_.__" )#</cfoutput></span></td>
										<td align="right"><cfif  propAdvice.getDegreeCourse()><span class="stat yes"></span><cfelse></cfif></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
				</cfloop>
				
			</div>
		</li>
	</ul>
</div>